/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __TERRAIN_BRUSH_MANAGER_H__
#define __TERRAIN_BRUSH_MANAGER_H__

#include "NgPrerequisites.h"

namespace PQEngine
{
	/*Manage a scene's terrain brush(alpha textures)
	*/
	class TerrainBrushManager
	{
	public:
		static const std::string ARCHIVE_NAME;
		
	public:
		TerrainBrushManager();
		~TerrainBrushManager();
		
		/*Add terrain texture file from local file system according to local file system file path.
		*/
		bool addBrushTextureFromLocalFS(std::string filePath);

		GPKFile* getTextureFile(int index);
		GPKFile* getTextureFile(std::string name);

		void clearBrushTexture();

		void selectBrush(std::string brush);
		void deselectBrush();

		void selectBrush(int index);
		
		inline float getBrushRadius()
		{
			return _brushSize;
		}

		inline bool hasBrushSelected()
		{
			return _brushSelected;
		}

		inline float* getBrushDataPtr()
		{
			return _brushData;
		}

		inline float getBrushSize()
		{
			return _brushSize;
		}

		inline float getBrushIntensity()
		{
			return _brushIntensity;
		}

		inline bool hasBrush(std::string brush)
		{
			StringVector::iterator it = find(_nameList.begin(),_nameList.end(),brush);
			if(it!=_nameList.end()){
				return true;
			}else{
				return false;
			}
		}

		inline int getNumTexture()
		{
			int size=_nameList.size();
			return size;
		}

		inline std::string getTextureName(int index)
		{
			int size=_nameList.size();
			if(index>=0&&index<size){
				return _nameList[index];
			}
			return "";//or return procedure build texture?
		}

		inline void select(int index)
		{
			_selectedIndex=index;
		}

		inline int getSelected(int index)
		{
			return _selectedIndex;
		}
	private:
		void setBrushImage(Ogre::Image& image);
		void loadTexture(int index);
	private:
		GPKArchive* _archive;
		StringVector _nameList;

		int _selectedIndex;
		float _brushSize;
		float _brushIntensity;
		float* _brushData;
		bool _brushSelected;
		Ogre::TexturePtr _decalTexture;//brush decal texture

	};
}

#endif
